//
//  CMTCheckBoxView.m
//  ExcellentHome
//
//  Created by 陈区 on 13-12-4.
//  Copyright (c) 2013年 陈区. All rights reserved.
//

#import "CMTCheckBoxView.h"

@implementation CMTCheckBoxView
@synthesize checked;
@synthesize checkBoxDelegate;

- (id)initWithFrame:(CGRect) aFrame normalImage:(UIImage *)normalImage checkedImage:(UIImage *)checkedImage
{
    if(self = [super initWithFrame:aFrame])
    {
        m_imgNormal = normalImage;
        m_imgChecked = checkedImage;
        btnCheck = [UIButton buttonWithType:UIButtonTypeCustom];
        btnCheck.frame = aFrame;
        [btnCheck setImage:m_imgNormal forState:UIControlStateNormal];
        [btnCheck setImage:m_imgChecked forState:UIControlStateSelected];
        btnCheck.contentMode=UIViewContentModeCenter;
        [btnCheck addTarget:self action:@selector(onBtnCheckClicked:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:btnCheck];
        
        checked = NO;
        btnCheck.selected = NO;
        
    }
    return self;
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/


- (void)onBtnCheckClicked:(UIButton *)sender
{
    checked = !checked;
    sender.selected = checked;
    [checkBoxDelegate checkBoxDidClicked:self];
}

//点击多选框
- (void)clickedCheckBoxForChecked:(BOOL)isChecked
{
    checked = isChecked;
    btnCheck.selected = checked;
    [checkBoxDelegate checkBoxDidClicked:self];
}

- (void)setChecked:(BOOL)aChecked
{
    checked = aChecked;
    btnCheck.selected = checked;
}



@end
